{include file="public/nheader"}
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="status" lay-verify="">
                                <option value="">状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>正常</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>冻结</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="type" lay-verify="">
                                <option value="">代理类型</option>
                                <option value="3" {if !empty(input('get.type')) && input('get.type')==3}selected{/if}>
                                    区域代理</option>
                                <option value="5" {if !empty(input('get.type')) && input('get.type')==4}selected{/if}>
                                    区划代理</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="备注|账号|手机号" />
                        </div>
                    </div>

                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>

                        <!-- // 打开添加页面 -->
                        <button class="layui-btn icon-btn" lay-maxmin="true" lay-open="" data-title="添加"
                            data-area="60%,80%" data-url="/agent/agent_edit">添加
                        </button>
                        <!-- // 删除所有 -->
                        <!-- <button class="layui-btn icon-btn layui-btn-danger" lay-batch="lay-tableList"
                            data-url="/agent/agent_del">批量删除
                        </button> -->
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>

<script type="text/html" id="datagrid-toolbar">
</script>
<!-- // 列表状态栏 -->
<script type="text/html" id="columnStatus">
     <input type="checkbox" lay-filter="switchStatus" data-url="/agent/agent_status?id={{d.id}}&field=status" lay-skin="switch"
     {{d.status==1?'checked':''}}   lay-text="正常|冻结"   />
</script>

<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <!--<a class="layui-table-text" lay-open data-title="套餐二维码" data-area="500px,550px" data-url="/agent/agent_qrcode?id={{d.id}}" >套餐二维码</a>
    <div class="layui-divider layui-divider-vertical"></div>-->
<a class="layui-table-text" lay-open data-title="编辑" data-area="60%,80%" data-url="/agent/agent_edit?id={{d.id}}">编辑</a>
<div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" data-url="/agent/index_exc?id={{d.id}} " data-reload="self" lay-ajax=""
    data-confirm="已导入项目不会重复导入,数据越多导入时间将越长,请确定要进行此操作吗？">导入项目、套餐</a>
{{# if(d.id !=1){ }}
<div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" data-url="/agent/agent_del?id={{d.id}}" data-title=" 执行该操作后代理区域和绑定师傅街道会删除"
    lay-event="del">删除</a>
{{# } }}
</script>
<script type="text/html" id="tableBar1">
    <a class="layui-table-text" lay-open data-title="管理区域" data-area="80%,90%" data-url="/agent/agentarea?agentid={{d.id}}" >查看</a>
</script>
<script type="text/html" id="tableBar3">
    <a class="layui-table-text" lay-open data-title="产品管理" data-area="80%,90%" data-url="/agent/product?agentid={{d.id}}" >查看({{d.product}})</a>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {

        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        form.on("submit(formSearch)", function (post) {
            // 获取用户id
            if (post.field.province || post.field.city || post.field.area || post.field.street) {
                if (!post.field.type) {
                    layer.error('请填写合伙人类型');
                    return false;
                }
            }
            layui.$.get("{:url('')}", post.field, function (res) {
                if (res.code == 200) {
                    table.reload("lay-tableList", {
                        page: {
                            curr: 1
                        },
                        where: post.field
                    })
                }
                else {
                    layer.error(res.msg);
                }
            }, 'json');

            return false;
        })
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , cols: [[
                // { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'nickname', width: 200, align: 'center', title: '备注' },
                { field: 'agentname', width: 200, align: 'center', title: '上级合伙人' },
                { align: 'center', width: 100, toolbar: '#tableBar1', title: '责任区域' },
                { align: 'center', width: 100, toolbar: '#tableBar3', title: '产品' },
                {
                    field: 'yyopen', align: 'center', width: 120, title: 'N元活动', templet: function (d) {
                        if (d.yyopen == 1) {
                            return '关闭';
                        } else {
                            return '开启';

                        }
                    }
                },
                // {
                //     field: 'openid', align: 'center', width: 120, title: '绑定微信', templet: function (d) {

                //         return d.openid ? '<a class="layui-badge layui-bg-blue" data-url="/agent/agent_status?id=' + d.id + '&field=openid" lay-ajax="" data-confirm data-reload="self">解绑</a>' : '<span class="layui-badge">未绑定</span>';
                //     }
                // },
                { field: 'accounts', width: 200, align: 'center', title: '账号' },
                { field: 'mobile', width: 200, align: 'center', title: '手机' },
                { field: 'created', width: 200, align: 'center', title: '创建时间' },
                { field: 'status', align: 'center', width: 120, templet: '#columnStatus', title: '状态' },
                { align: 'center', width: 350, toolbar: '#tableBar', title: '操作' },
            ]]
        })
    })
</script>